package GUI;

import Utils.MSJ_JOptionPane;

/**
 * <b>Use this class to validate Email - password - numbers only - Characters
 * only </b><br><b> NO Special characters - Max Characters - Min Characters.</b>
 *
 * @author Mohamed Tarek Salama
 * @version 1.2 BETA
 */
public class MSJ_Validators {

    /**
     * check the e-mail that is it has a <b>@</b> and must followed by
     * <b>Domain.com</b>
     *
     * @param email : String mail format.
     */
    public void ValidateEmail(String email) {
        if (!email.matches("^([^.@]+)(\\.[^.@]+)*@([^.@]+\\.)+([^.@]+)$")) {
            MSJ_JOptionPane.show_Error_Message("Invalid E-mail address\n" + email);
        }
    }

    /**
     * check the e-mail that is it has a <b>@</b> and must followed by
     * <b>Domain.com</b>
     *
     * @param email : mail string format.
     * @return boolean
     */
    public boolean Validate_Email(String email) {
        if (!email.matches("^([^.@]+)(\\.[^.@]+)*@([^.@]+\\.)+([^.@]+)$")) {
            return false;
        } else {
            return true;
        }
    }

    /**
     * match a string at least <b>6 characters</b> long, with at least <b>one
     * lower case</b> and at least <b>one uppercase</b> letter and at least
     * <b>one number</b>.
     *
     * @param pass : password string.
     */
    public void ValidatePassword(String pass) {
        if (!pass.matches("((?=.*\\d)(?=.*[a-z])(?=.*[A-Z]).{6,})")) {
            MSJ_JOptionPane.show_Error_Message("Weak Password\nPassword length must "
                    + "be grater than 6 characters\nPlease use Upper & Lower cases & Numbers");
        }
    }

    /**
     * match a string at least <b>6 characters</b> long, with at least <b>one
     * lower case</b> and at least <b>one uppercase</b> letter and at least
     * <b>one number</b>.
     *
     * @param pass : password string.
     * @return boolean
     */
    public boolean Validate_Password(String pass) {
        if (!pass.matches("((?=.*\\d)(?=.*[a-z])(?=.*[A-Z]).{6,})")) {
            return false;
        } else {
            return true;
        }
    }

    /**
     * match the <b>numbers</b> only, if the text contains Characters it show
     * <b>JOptionPane</b> error
     *
     * @param numbers : number string.
     */
    public void ValidateNumbersOnly(String numbers) {
        if (!numbers.matches("^[0-9]+$")) {
            MSJ_JOptionPane.show_Error_Message("Please, Enter numbers only");
        }
    }

    /**
     * match the <b>numbers</b> only, if the text contains Characters it
     * <b>Return</b> false.
     *
     * @param numbers : number string.
     * @return boolean
     */
    public boolean Validate_NumbersOnly(String numbers) {
        if (!numbers.matches("^[0-9]+$")) {
            return false;
        } else {
            return true;
        }
    }

    /**
     * match the <b>Characters</b> only and when the text contains numbers,<br>
     * it show <b>JOptionPane</b> error
     *
     * @param characters : character string.
     */
    public void ValidateCharOnly(String characters) {
        if (!characters.matches("^[a-zA-Z]+$")) {
            MSJ_JOptionPane.show_Error_Message("Please, Enter characters only");
        }
    }

    /**
     * match the <b>Characters</b> only and when the text contains numbers,<br>
     * it returns false.
     *
     * @param characters : character string.
     * @return boolean
     */
    public boolean Validate_CharOnly(String characters) {
        if (!characters.matches("^[a-zA-Z]+$")) {
            return false;
        } else {
            return true;
        }
    }

    /**
     * match the text not to include any special characters.<br> if the text
     * contains any special characters it show <b>JOptionPane</b> error
     *
     * @param characters : character string.
     */
    public void ValidatenoSpecialChar(String characters) {
        if (!characters.matches("[a-zA-Z0-9 ]*")) {
            MSJ_JOptionPane.show_Error_Message("Please, Enter Only Digits and Characters");
        }
    }

    /**
     * match the text not to include any special characters.<br> if the text
     * contains any special characters it return <b>False</b>
     *
     * @param characters : character string.
     * @return boolean
     */
    public boolean Validate_noSpecialChar(String characters) {
        if (!characters.matches("[a-zA-Z0-9 ]*")) {
            return false;
        } else {
            return true;
        }
    }

    /**
     * Check the <b>length</b> of the text, if the text length is more than the
     * <br> <b>minimum length</b> it will show <b>JOptionPane</b> error.
     *
     * @param txt : text string.
     * @param minlenght : Integer minimum length of the text string.
     */
    public void ValidateMinLenght(String txt, int minlenght) {
        if (txt.length() < minlenght) {
            MSJ_JOptionPane.show_Error_Message("Please, Enter more than " + minlenght + " characters and digits");
        }
    }

    /**
     * Check the <b>length</b> of the text, if the text length is more than the
     * <br> <b>minimum length</b> it will return <b>False</b>.
     *
     * @param txt : text string.
     * @param minlenght : Integer minimum length of the text string.
     * @return boolean
     */
    public boolean Validate_MinLenght(String txt, int minlenght) {
        if (txt.length() < minlenght) {
            return false;
        } else {
            return true;
        }
    }

    /**
     * Check the <b>length</b> of the text, if the text length is less than the
     * <br> <b>maximum length</b> it will show <b>JOptionPane</b> error.
     *
     * @param txt : text string.
     * @param maxlenght : Integer maximum length of the text string.
     */
    public void ValidateMaxLenght(String txt, int maxlenght) {
        if (txt.length() > maxlenght) {
            MSJ_JOptionPane.show_Error_Message("Please, Enter only " + maxlenght + " characters and digits");
        }
    }

    /**
     * Check the <b>length</b> of the text, if the text length is less than the
     * <br> <b>maximum length</b> it will return <b>False</b>.
     *
     * @param txt : text string.
     * @param maxlenght : Integer maximum length of the text string.
     * @return boolean
     */
    public boolean Validate_MaxLenght(String txt, int maxlenght) {
        if (txt.length() > maxlenght) {
            return false;
        } else {
            return true;
        }
    }
}